package com.day13_Internet;

import java.io.IOException;
import java.net.*;

/**
 * @ClassName: UDP_demo
 * @Author: zw
 * @Description: 出百万拳，行万里路；
 * @Create 2024/3/24-13:36
 * @Version 1.0
 */
public class UDP_send_demo {
    public static void main(String[] args) throws IOException {
        DatagramSocket socket = new DatagramSocket();

        // 2. 创建数据并且把数据打包 DatagramPacket（byte，lenght，address，port）
        byte[] bys = "hello,world".getBytes();
        int length = bys.length;
        InetAddress address = InetAddress.getByName("192.168.3.7");
        int port = 4444;
        DatagramPacket dp = new DatagramPacket(bys, length, address, port);
        //3.
        socket.send(dp);
        // 4.
        socket.close();
    }
}
